package com.ruoyi.web.ydz.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.ydz.domain.Report;
import com.ruoyi.web.ydz.service.IReportService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 举报投诉Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/ydz/report")
public class ReportController extends BaseController
{
    @Resource
    private IReportService reportService;

    /**
     * 查询举报投诉列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(Report report)
    {
        startPage();
        List<Report> list = reportService.selectReportList(report);
        return getDataTable(list);
    }

    /**
     * 导出举报投诉列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:report:export')")
    @Log(title = "举报投诉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Report report)
    {
        List<Report> list = reportService.selectReportList(report);
        ExcelUtil<Report> util = new ExcelUtil<Report>(Report.class);
        util.exportExcel(response, list, "举报投诉数据");
    }

    /**
     * 获取举报投诉详细信息
     */
    @PreAuthorize("@ss.hasPermi('ydz:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(reportService.selectReportById(id));
    }

    /**
     * 新增举报投诉
     */
    @PreAuthorize("@ss.hasPermi('ydz:report:add')")
    @Log(title = "举报投诉", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Report report)
    {
        return toAjax(reportService.insertReport(report));
    }

    /**
     * 修改举报投诉
     */
    @PreAuthorize("@ss.hasPermi('ydz:report:edit')")
    @Log(title = "举报投诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Report report)
    {
        return toAjax(reportService.updateReport(report));
    }

    /**
     * 删除举报投诉
     */
    @PreAuthorize("@ss.hasPermi('ydz:report:remove')")
    @Log(title = "举报投诉", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reportService.deleteReportByIds(ids));
    }

    /*
    * 处理投诉状态
    * */
    @PreAuthorize("@ss.hasPermi('ydz:report:edit')")
    @Log(title = "处理投诉状态", businessType = BusinessType.UPDATE)
    @PostMapping("/handleComplaint")
    public AjaxResult handleComplaint(@RequestBody Report report){
        return reportService.handleComplaint(report);
    }

}
